
#include "util.h"

unsigned int Util::SaturatingAdd(unsigned int val,unsigned int add){
    unsigned long l_val = (unsigned long)val;
    unsigned long l_add = (unsigned long)add;

    if (l_val + l_add > UINT_MAX){
        return UINT_MAX;
    }
    return val + add;
}


unsigned int Util::SaturatingSub(unsigned int val,unsigned int sub){
    if (val < sub){
        return 0;
    }

    return val - sub;
}


bool Util::IsAsciiDigit(char c){
    return c >= '0' && c <= '9';

}


bool Util::IsAsciiPunctuation(char c){
    return (c>='!' and c <= '/') 
        || (c>=':' and c<='@')
        || (c>='[' and c<='`')
        || (c>='{' and c<='~');

}

bool Util::IsAsciiWhitespace(char c){
    return c == ' ';

}

bool Util::EndsWith(std::string content,std::string str){
    return content.substr(content.length() - str.length()) == str;

}


bool Util::IsSeperator(char c){
    return Util::IsAsciiPunctuation(c)|| Util::IsAsciiWhitespace(c);
}


